#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=3e4+10;
int n,m,stac[MAXN],top;
struct LCT
{
	int c[MAXN][2],sum[MAXN],val[MAXN],fa[MAXN];
	bool rev[MAXN];
	void push_up(int o)
	{
		sum[o]=sum[c[o][0]]+sum[c[o][1]]+val[o];
		return;
	}
	void reverse(int o)
	{
		if(!o)return;
		rev[o]^=1;
		swap(c[o][0],c[o][1]);
		return;
	}
	void push_down(int o)
	{
		if(rev[o])
		{
			reverse(c[o][0]);
			reverse(c[o][1]);
			rev[o]=false;
		}
		return;
	}
	bool isroot(int o)
	{
		return !(c[fa[o]][0]==o||c[fa[o]][1]==o);
	}
	void rotate(int x)
	{
		int y=fa[x],z=fa[y],dy=c[y][1]==x,dz=c[z][1]==y;
		if(!isroot(y))c[z][dz]=x;
		c[y][dy]=c[x][dy^1];
		fa[c[y][dy]]=y;
		c[x][dy^1]=y;
		fa[y]=x;
		fa[x]=z;
		push_up(y);
	}
	void splay(int x)
	{
		stac[top=1]=x;
		for(int i=x;!isroot(i);i=fa[i])stac[++top]=fa[i];
		while(top)push_down(stac[top--]);
		while(!isroot(x))
		{
			int y=fa[x],z=fa[y];
			if(!isroot(y))
			{
				if(c[y][1]==x^c[z][1]==y)rotate(x);
				else rotate(y);
			}
			rotate(x);
		}
		push_up(x);
		return;
	}
	void access(int o)
	{
		for(int i=0;o;i=o,o=fa[o])
		{
			splay(o);
			c[o][1]=i;
		}
	}
	int findroot(int o)
	{
		access(o);
		splay(o);
		while(c[o][0])o=c[o][0];
		return o;
	}
	void makeroot(int o)
	{
		access(o);
		splay(o);
		reverse(o);
		return;
	}
	void link(int x,int y)
	{
		makeroot(x);
		fa[x]=y;
		return;
	}
	void solve()
	{
		while(m--)
		{
			char op[10];
			scanf("%s",op);
			int x=read(),y=read();
			if(op[0]=='b')
			{
				if(findroot(x)==findroot(y))puts("no");
				else puts("yes"),link(x,y);
			}
			else if(op[0]=='p')
			{
				makeroot(x);
				val[x]=y;
				push_up(x);
			}
			else
			{
				if(findroot(x)!=findroot(y))puts("impossible");
				else
				{
					makeroot(x);
					access(y);
					splay(y);
					printf("%d\n",sum[y]);
				}
			}
		}
	}
}T1;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)T1.sum[i]=T1.val[i]=read();
	m=read();
	T1.solve();
	return 0;
}
